import javax.swing.*;
import java.security.PublicKey;
import java.util.Stack;

public class JsView extends JFrame {
    public JsView() {
        JLabel l_title = new JLabel("简易计算器");
        JLabel l_num1 = new JLabel("运算数1");
        JLabel l_num2 = new JLabel("运算数2");
        JLabel l_fu = new JLabel("运算符");
        JLabel l_js = new JLabel("计算");
        JLabel l_resout = new JLabel("结果");
        JTextField t_num1 = new JTextField();
        JTextField t_num2 = new JTextField();
        JComboBox<String> comboBox = new JComboBox(new String[]{"+", "-", "*","/"});
        JButton result = new JButton("=");
        JTextField output = new JTextField();
        JPanel panel = new JPanel();
        panel.setLayout(null);
        l_title.setBounds(150, 20, 100, 50);
        l_num1.setBounds(60, 80, 50, 20);
        l_fu.setBounds(120, 80, 50, 20);
        l_num2.setBounds(180, 80, 50, 20);
        l_js.setBounds(250, 80, 50, 20);
        l_resout.setBounds(290, 80, 50, 20);
        t_num1.setBounds(60, 100, 50, 20);
        comboBox.setBounds(120, 100, 50, 20);
        t_num2.setBounds(180, 100, 50, 20);
        result.setBounds(250, 100, 50, 20);
        output.setBounds(310, 100, 50, 20);
        result.addActionListener(e -> {
            Double num1 = Double.parseDouble(t_num1.getText());
            Double num2 = Double.parseDouble(t_num2.getText());
            String fu = comboBox.getSelectedItem().toString();
            Double js = .0;
            switch (fu){
                case "+":
                    js=num1+num2;
                    break;
                case "-":
                    js=num1-num2;
                    break;
                case "*":
                    js=num1*num2;
                    break;
                case "/":
                    js=num1/num2;
                    break;

            }
            output.setText(String.valueOf(js));
        });
        panel.add(l_title);
        panel.add(l_num1);
        panel.add(l_num2);
        panel.add(l_fu);
        panel.add(l_js);
        panel.add(l_resout);
        panel.add(t_num1);
        panel.add(t_num2);
        panel.add(comboBox);
        panel.add(result);
        panel.add(output);
        panel.setVisible(true);
        this.setVisible(true);
        this.add(panel);
        this.setTitle("简易计算器");
        this.setSize(400,300);

    }
    public static void main(String[] args) {
        new JsView();
    }
}
